package com.example.helloworld

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import java.util.ArrayList

class PicAdapter(val pics: ArrayList<Pictures>) : RecyclerView.Adapter<PicAdapter.PicViewHolder>() {

    inner class PicViewHolder(itemView: View) :RecyclerView.ViewHolder(itemView){
        val img=itemView.findViewById<ImageView>(R.id.avatar)
        val desc=itemView.findViewById<TextView>(R.id.desc)
        val name=itemView.findViewById<TextView>(R.id.name)
        val img1=itemView.findViewById<ImageView>(R.id.avatar1)
       val desc1=itemView.findViewById<TextView>(R.id.desc1)
        val name1=itemView.findViewById<TextView>(R.id.name1)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PicViewHolder {
       val view = LayoutInflater.from(parent.context).inflate(R.layout.item_pics,parent,false)
        val holder = PicViewHolder(view)
        return holder
    }

    override fun onBindViewHolder(holder: PicViewHolder, position: Int) {
        val pic = pics[position]
        holder.name.text = pic.name
        holder.desc.text = pic.description
        holder.img.setImageResource(pic.avatar)
        val pic1 = pics[position+1]
       holder.name1.text = pic1.name
        holder.desc1.text = pic1.description
        holder.img1.setImageResource(pic1.avatar)
    }

    override fun getItemCount(): Int {
       return pics.size
    }

}